/*
 * Copyright (c) 2018-2028 兰州安众信息科技有限公司 All Rights Reserved.
 * ProjectName: 甘肃九建OA系统
 */

package com.book.manager.controller.authentication;


import com.book.manager.base.result.Result;
import com.book.manager.dto.LoginReq;
import com.book.manager.dto.Token;
import com.book.manager.model.User;
import com.book.manager.service.authentication.MyAuthenticationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("/login")
@Api(tags = {"用户登录"})
public class MyAuthenticationController {

    @Autowired
    MyAuthenticationService myAuthenticationService;

    @ApiOperation(value = "账号登录")
    @PostMapping("/loginByAccount")
    @ResponseBody
    public Result<Token> loginByAccount(HttpServletRequest request,
                                            @RequestBody LoginReq req) throws IOException {
        try {
            return Result.success(myAuthenticationService.loginWithUserNameAndPw(request, req));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
    }

}
